<?php
/**
* @package   auto_occasion
* @subpackage statistique
* @author    your name
* @copyright 2011 your name
* @link      http://www.yourwebsite.undefined
* @license    All rights reserved
*/

class BoStatistiqueCtrl extends jController {

    public $pluginParams = array(
                                    '*'=>array('auth.required'=>true,
                                    'jacl2.right'=>'admin.compte.gerer'
                                    )
                            );


    /**
    * Affiche par représentation graphique les stats des formules / mois
    */
    function index() {
        $rep = $this->getResponse('html');
        $rep->menusActifs = adminHtmlResponse::MENU_STATISTIQUE ;

        $rep->addCSSLink($GLOBALS['gJConfig']->urlengine['basePath'].'design/back/css/jquery-ui.css');
        $rep->addJSLink($GLOBALS['gJConfig']->urlengine['basePath'].'design/back/js/jquery-ui.min.js');

        jClasses::inc('statistique~statSrv');
        
        $dateDebut = $this->stringParam('debut', '');
        $dateFin   = $this->stringParam('fin', '');

        // initialisation
        $statParDate = $statCurrentMonth = $stat1 = $stat2 = array();
        $date = null;
        if ($dateDebut && $dateFin) {
            $statParDate = statSrv::getStatsByDate ($dateDebut, $dateFin);
//            print_r($statParDate);die();
        } else {

            // récupération des trois derniers mois
            $date = statSrv::getThreeLastMonthAndYear();

            // mois courant
            $statCurrentMonth = statSrv::getStats ($date->months[0], $date->year[0]);

            // le mois précédent
            $stat1 = statSrv::getStats ($date->months[1], $date->year[1]);

            // le 3è avant dernier mois
            $stat2 = statSrv::getStats ($date->months[2], $date->year[2]);
        }

        $rep->bodyTpl = 'statistique~BoStatistique';

        $rep->body->assign('statCurrentMonth', $statCurrentMonth );
        $rep->body->assign('stat1', $stat1 );
        $rep->body->assign('stat2', $stat2 );
        $rep->body->assign('statParDate', $statParDate );
        $rep->body->assign('dateDebut', $dateDebut );
        $rep->body->assign('dateFin', $dateFin );
        $rep->body->assign('date', $date );


        return $rep;
    }
}

